package com.bianguo.android.tencentpushdemo.view.activity;

import android.os.Bundle;
import android.widget.ListView;

import com.bianguo.android.tencentpushdemo.R;
import com.bianguo.android.tencentpushdemo.adapters.WeatherAdapter;
import com.bianguo.android.tencentpushdemo.entity.Weather;
import com.bianguo.android.tencentpushdemo.tasks.LoadWeatherTask;
import com.bianguo.android.tencentpushdemo.tasks.WeatherTask;

import java.util.ArrayList;

import butterknife.BindView;

public class WeatherActivity extends BaseActivity implements LoadWeatherTask.LoadWeatherListener {

    @BindView(R.id.weather_list)
    ListView weatherLv;

    private final String WEATHER_URL = "http://www.12346.com/";
    private LoadWeatherTask loadWeatherTask;
    private ArrayList<Weather> weathers;
    private WeatherAdapter weatherAdapter;
    private WeatherTask weatherTask;

    @Override
    public int layoutId() {
        return R.layout.activity_weather;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        weathers = new ArrayList<>();
        weatherAdapter = new WeatherAdapter(this, weathers);
        weatherLv.setAdapter(weatherAdapter);
    }

    @Override
    public void initData() {
//        loadWeatherTask = new LoadWeatherTask(this);
//        loadWeatherTask.execute("http://home.meishichina.com/show-top-type-recipe.html");

        weatherTask = new WeatherTask();
        weatherTask.execute(WEATHER_URL);
    }

    @Override
    public void loadWeather(ArrayList<Weather> weathers) {
        this.weathers.clear();
        this.weathers.addAll(weathers);
        weatherAdapter.notifyDataSetChanged();
    }
}
